package org.sgx.gwteditors.testgallery.gallery;

import java.util.Map;

import org.sgx.gwteditors.client.impl1.simple.IntegerEditorEntry;
import org.sgx.gwteditors.client.util.TestUtil;

import com.google.gwt.resources.client.ExternalTextResource;
import com.google.gwt.user.client.ui.Panel;

public class ErrorsTest1 implements Test {	
	
	@Override
	public void test(Panel parent) {
		IntegerEditorEntry ed1 = new IntegerEditorEntry();
		parent.add(ed1);
		ed1.setText("this is not an int"); // like the user just typed this.
		Integer val = ed1.flush(); //null because string is not parseable to integer.
		if(val==null && ed1.getErrors().size()>0) {
			ed1.setText("bad value. Reason: "+ed1.getErrors().get(0).toString());
		}
	}

	
	//test stuff
	@Override
	public String getName() {
		return "Errors 1";
	}

	@Override
	public String[] getTags() {		
		return null;
	}

	@Override
	public String getDescription() {
		return "Show how to use the errors api - a way editors have to tell use something is wrong with what the user has edited.";
	}
	@Override
	public Map<String, ExternalTextResource> getJavaSources() {
		return TestUtil.getResource(getName(), TestResources.INSTANCE.ErrorsTest1());
	}
//	@Override
//	public String[] getJavaSources() {
//		return new String[]{TestResources.INSTANCE.ErrorsTest1().getText()};
//	}
}
